import { ExecutionContext, NestInterceptor } from "@nestjs/common";
import {
  Observable,
  tap,
  map,
} from "rxjs";


// 通过拦截器来处理路由处理函数响应的值是一个 null 和 undefined 情况
export class ExcludeNullInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next): Observable<any> | Promise<Observable<any>> {
    console.log('ExcludeNullInterceptor start')
    return next.handle().pipe(
      map(data => {
        console.log('ExcludeNullInterceptor end', data)
        return data === null || data === undefined ? '' : data
      })
    )
  }

}
